package com.mdl.book.util;

import java.sql.*;

public class DB {
	static final String dbDriver = "com.mysql.jdbc.Driver";
	static final String dbURL = "jdbc:mysql://localhost:3306/bookManager";
	
	public static Connection getConn(){
		Connection conn = null;
		try{
			Class.forName(dbDriver);
			conn = DriverManager.getConnection(dbURL,"root","modonglin");
		}catch(ClassNotFoundException e){
			e.printStackTrace();
		}catch(SQLException sqle){
			sqle.printStackTrace();
		}
		return conn;
	}
	
	public static void closeConn(Connection conn){
		try{
			if(conn != null){
				conn.close();
				conn = null;
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	
	public static void closeStmt(Statement stmt){
		try{
			if(stmt != null){
				stmt.close();
				stmt = null;
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	
	public static void closeResultSet(ResultSet rs){
		try{
			if(rs != null){
				rs.close();
				rs = null;
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
}
